<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: show_curve.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 
if ($jl_func == "showcurve_getchartdata")
{
	$roundsCode = array();
	foreach ($rounds AS $temp) {
	  $roundsCode[] = $temp->matchcode;
	}
	
	// colors defined for ranking table lines
	foreach($colors as $color) {
	  foreach ($roundsCode AS $matchcode) {
	    for ($n=$color['from'];$n <= $color['to'];$n++) {
	      $lines[$color['color']][$n][] = $n;
	    }
	  }
	}
	
	$xLabel = implode(',', $roundsCode);
	
	// load the utility class for the graph
	include( JL_FRONTEND_PATH.'/lib/open-flash-chart/open-flash-chart.php' );
	
	$g = new graph();
	$g->set_x_labels( array($xLabel));
  
	// backgound color of flash statistic
  $g->bg_colour = $overall_config['bg_colour'];
  $g->title( ' ', '{font-size: 12px;}' );
  
  // inner background color with gradient
  if ($overall_config['inner_bg_gradient_1'] != '') {
    $g->set_inner_background( $overall_config['inner_bg_gradient_1'], $overall_config['inner_bg_gradient_2'], $overall_config['inner_bg_gradient_orientation'] );
  }
  
  foreach ($lines AS $key => $value) {
    foreach ($value AS $line) {
	    $g->set_data($line);
	    $g->line( 5, $key, '', 10 );
	  }
	}
	if ($team[$division] > 0 && count($platzierungen[$division]) > 0 && $team2[$division]!=$team[$division]) {
	  $g->set_data($platzierungen[$division]);
	  $g->line_dot( $overall_config['line1_strength'], $overall_config['line1_dot_strength'], $overall_config['line1'], jl_utf8_convert($a[$division][$team[$division]]->team->name), 12 );
		$query = sprintf("SELECT logo_big FROM #__joomleague_clubs clubs
             LEFT JOIN #__joomleague_teams teams ON clubs.id = teams.club_id
             WHERE teams.id = %s", $team[$division]);
    $database->setQuery($query);
    $g->set_bg_image( _JOOMLA_JL_LIVE_SITE.'/'.$database->loadResult(), 'doubleleft','middle', 10);
  }
	if ($team2[$division] >0 && count($platzierungen2[$division]) >0  && $team2[$division]!=$team[$division]) {
	  $g->set_data($platzierungen2[$division]);
	  $g->line_dot( $overall_config['line2_strength'], $overall_config['line2_dot_strength'], $overall_config['line2'], jl_utf8_convert($a[$division][$team2[$division]]->team->name), 12 );
    $query = sprintf("SELECT logo_big FROM #__joomleague_clubs clubs
             LEFT JOIN #__joomleague_teams teams ON clubs.id = teams.club_id
             WHERE teams.id = %s", $team2[$division]);
    $database->setQuery($query);
    $g->set_bg_image2( _JOOMLA_JL_LIVE_SITE.'/'.$database->loadResult(), 'doubleright', 'middle' ,5);
  }

	$g->set_y_max( 1 );
	$g->set_y_min( count($a[$division]) );
	$g->y_label_steps(count($a[$division])-1);
	//$g->y_lable_style='none';
	$g->set_y_right_min( count($a[$division]) );

  $g->set_y_right_max( 1 );
	$g->x_axis_colour( $overall_config['x_axis_colour'], $overall_config['y_axis_colour_inner'] );
	$g->set_x_legend( _JL_MATCHDAY, 12, $overall_config['x_axis_colour_inner'] );
  // y-axis color (color for left y-axis, color for inner y-axis)
  $g->y_axis_colour( $overall_config['y_axis_colour'], $overall_config['x_axis_colour_inner'] );
  $g->set_tool_tip( _JL_TABLE_POSITION.': #val#' );  
  $g->set_y_legend( _JL_TABLE_POSITION, 12, $overall_config['y_axis_colour'] );
	echo  $g->render(); // Method doesn't really render, but it returns a drawlist as multiline text string
	exit();
}
?>
<script type="text/javascript">
// <![CDATA[
function findSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
function reload()
{
    tmp = findSWF("chart");
    x = tmp.reload();
}
<?php
foreach ($allteams AS $division => $rank) { ?>
  function reload_<?php echo $division;?>()
{
    tmp = findSWF("chart_<?php echo $division;?>");
    var reloadstring = '<?php echo jl_utf8_convert($url_string);?>&whatdivision=<?php echo $division;?>'+
     '&tid='+document.getElementById('tid_<?php echo $division;?>').options[document.getElementById('tid_<?php echo $division;?>').selectedIndex].value+
     '&tid2='+document.getElementById('tid2_<?php echo $division;?>').options[document.getElementById('tid2_<?php echo $division;?>').selectedIndex].value;
    x = tmp.reload(reloadstring);
}
<?php } ?>
// ]]>
</script>
<div id="joomleague">
<!-- Header with Project Name-->
<?php $print_icon = 0 ; // set to 1 or use overall template to enable print function ?>
<div class="componentheading" <?php if ($print_icon == "1" OR $overall_config['show_print_button'] == "1") echo 'style="float:left;"';?>><?php echo $htmlHelper->showTitle($joomleague, $overall_config['project_heading_type']); ?></div>
<!-- print -->
<?php if ($print_icon == "1" OR $overall_config['show_print_button'] == "1") {
$htmlHelper->PrintIcon( $row, $params, false, '' );
};?>
<!-- print End -->

<!-- Header END -->
<?php
foreach ($allteams AS $division => $rank) { 
  ?>
<!-- sectionheading e.g. ranking aso -->
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading"><a name="division<?php echo $division;?>"></a>
<?php
$divname = '';
if ($division > 0) {
  $thisdiv = new LeagueDivision($database);
  $thisdiv->load($division);
  $divname = $thisdiv->name;
}
		 echo _JL_CURVE.' '.$divname;?></td></tr>
		<tr><td style="text-align:right" nowrap="nowrap"><?php
		echo $htmlHelper->show_curve_form ($url_string, $selectoptions[$division], $teamlist2options[$division], $team[$division], $team2[$division], $division);
?>
		</td>
	</tr>
</table>
<!-- sectionheading ends -->


<br />
<?php
//$htmlHelper->init_curve_js ( $platzierungen, $platzierungen2 )
  $htmlHelper->open_flash_chart_object( '100%', $height[$division], _JOOMLA_JL_LIVE_SITE."/".str_replace("&amp;", "%26", JL_COMPONENT_LINK_NOHTML)."%26divLevel=".$divLevel."%26tid="
  .$team[$division]."%26tid2=".$team2[$division]."%26func=showcurve_getchartdata%26p=".$joomleague->id."%26whatdivision="
  .$division.str_replace("&amp;", "%26", JL_ITEMID_SUFFIX), true, $division );
?>
<br />

<!-- colors legend -->
<?php if ($table_config['show_colors_legend']==1){;?>
<table width="96%" align="center" cellpadding="0" cellspacing="0" class="">
  <tr>
<?php
       $htmlHelper->show_colors_legend($colors);
?>
  </tr>
</table>
<br />
<?php };?>
<!-- colors legend End -->
<?php
} ?>
<!-- Print Button START -->
<?php $back_button = 0 ; // set to 1 or use overall template to enable back button ?>
<?php if ($back_button > 0 OR $overall_config['show_back_button'] > 0) {;?>
<?php if ($overall_config['show_back_button'] == "1") echo '<div align="left">'; else echo '<div align="right">';?>
<?php
$params = & new mosParameters( '' );
$params->def( 'back_button', true );
$params->def( 'popup', false );
mosHTML::BackButton( $params );
echo "</div>";
};?>
<!-- Print Button END -->
</div>